<div class="bjui-pageHeader" style="background-color:#fefefe; border-bottom:none;">
    <form data-toggle="ajaxsearch" data-options="{searchDatagrid:$.CurrentNavtab.find('#datagrid-customer-list')}">
        <fieldset>
            <legend style="font-weight:normal;">页头搜索：</legend>
            <div style="margin:0; padding:1px 5px 5px;">
                <span>客户名称：</span>
                <input type="text" name="customer_name" class="form-control" size="15">

                <span>销售员：</span>
                <input type="hidden" name="sales_uid" >
                <input type="text" name="truename" id="truename" data-toggle="findgrid" data-options="{
                    include: 'sales_uid:id,truename',
                    dialogOptions: {title:'查找销售员'},
                    gridOptions: {
                        local: 'local',
                        dataUrl: '/admin/company/depart-user-lists',
                        columns: [
                            {name:'truename', label:'员工列表', width:100},
                        ]
                    }
                }" disabled>

                <div class="btn-group">
                    <button type="submit" class="btn-green" data-icon="search">开始搜索！</button>
                    <button type="reset" class="btn-orange" data-icon="times">重置</button>
                </div>
            </div>
        </fieldset>
    </form>
</div>
<div class="bjui-pageContent">
    <table class="table table-bordered" id="datagrid-customer-list" data-toggle="datagrid" data-options="{
        height: '100%',
        gridTitle : '客户列表',
           editMode: {dialog:{id:'customer-custom-save', url:'/admin/customer/custom-save', type:'get', title:'客户添加', width:700, height:500}},
           local: 'remote',
           showToolbar: true,
           toolbarItem:'add,export',
           dataUrl: '/admin/customer/list',
           editUrl: '/admin/customer/save',
           delUrl: '/admin/customer/del',
           delPK: 'id',
           linenumberAll: true,
           sortAll: false,
           contextMenuH: true,
           contextMenuB: true,
           showCheckboxcol: true,
           inlineEditMult: true,
           paging: {showPagenum:10, selectPageSize:'20,50,100', pageCurrent:1, pageSize:20},
           customEditbtns: {width:200,position:'replace'},
           fullGrid: true,
           {{--fieldSortable: false,--}}
            sortAll:true,
           filterThead: false,
           columnMenu: false,
           exportOption:{type:'file', options:{url:'admin/customer/export', type:'get', data: {_token : '{{ csrf_token() }}'}}}
        }">
        <thead>
        <tr>
            <th data-options="{name:'customer_name',align:'center',width:100}">客户名称</th>
            <th data-options="{name:'company_name',align:'center',width:100}">单位名称</th>
            <th data-options="{name:'avatars_url', render:'create_img_tag',align:'center',width:100}">头像</th>
            <th data-options="{name:'customer_level_title',align:'center',width:100}">客户分类</th>
            <th data-options="{name:'customer_no',align:'center',width:100}">客户编号</th>
            <th data-options="{name:'customer_tel',align:'center',width:100}">客户电话</th>
            <th data-options="{name:'customer_address',align:'center',width:100}">客户地址</th>

            <th data-options="{name:'contact_person',align:'center',width:100}">客户代表</th>
            <th data-options="{name:'contact_phone',align:'center',width:100}">客户代表电话</th>
            <th data-options="{name:'contact_address',align:'center',width:100}">客户代表地址</th>

            <th data-options="{name:'sales_name',align:'center',width:100}">销售员</th>
            <th data-options="{name:'merchandiser_name',align:'center',width:100}">跟单员</th>
            <th data-options="{name:'sort_id',align:'center',width:100}">排序</th>
            <th data-options="{name:'last_order_time',align:'center',width:100}">最近下单时间</th>
            <th data-options="{align:'center',render:customer_manage}">操作</th>
        </tr>
        </thead>
    </table>
</div>
<script>
    function customer_manage(value,data){
        var html = '<button type="button" class="btn-green" data-toggle="dialog" data-options="{id:\'customer-product-dialog\',fresh:true, url:\'/admin/customer/product-list\', title:\'客户材料\',max:true, data:{customer_id:' + data.id + '}}">材料</button>'
                + '<button type="button" class="btn-green" data-toggle="dialog" data-options="{id:\'customer-invoice-dialog\',fresh:true, url:\'/admin/customer/invoice-list\', title:\'客户开票信息\',max:true, data:{customer_id:' + data.id + '}}">票据</button>'
                + '<button type="button" class="btn-green" data-toggle="dialog" data-options="{id:\'customer-buyers-dialog\',fresh:true, url:\'/admin/buyers/list\', title:\'单位\', data:{customer_id:' + data.id + '}}">单位</button>'

                //+ '<button type="button" class="btn-green" onclick="setPassword('+ data.id+');">修改密码</button>'

                + '<button type="button" class="btn-green" data-toggle="edit.datagrid.tr">编辑</button>'
                + '<button type="button" class="btn-red" data-toggle="del.datagrid.tr">删除</button>';
        var address  = '<button type="button" class="btn-green" data-toggle="navtab" data-options="';
        address      += '{id:\'address-lists\',title:\''+data.customer_name+'-地址列表\',';
        address      += 'fresh:true,';
        address      += 'url:\'/admin/customer/address-list\',data:{customer_id:' + data.id + '}}';
        address      += '"> 地址</button>';
        return address+html

    }

    function setPassword(id){
        BJUI.alertmsg('prompt', '请输入新密码', {
        okCall: function(password) {
                if(password.length<6 || password.length>20){
                    BJUI.alertmsg('info', '密码应为6-20字符！')
                }
                else{
                    BJUI.ajax('doajax', {
                          url: '/admin/customer/set-password',
                          loadingmask: true,
                          data:{id:id,password:password},
                          okCallback: function(json, options) {

                          }
                    })
                }
            }
        });
    }

    function create_img_tag(value){
        return '<img src="'+value+'" width="100" height="100">';
    }

</script>